package com.woniuxy.educationplatform.controller;

import com.woniuxy.educationplatform.bean.KnowpointBean;
import com.woniuxy.educationplatform.bean.ProjectBean;
import com.woniuxy.educationplatform.bean.SubjectBean;
import com.woniuxy.educationplatform.service.IKnowpointService;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.xml.crypto.Data;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/knowpoint")

public class KnowpointController {

    @Resource
    private IKnowpointService knowpointServiceImpl;

    @RequestMapping("/findAll")
    public List<KnowpointBean> findAll(){
        System.out.println("开始查询所有知识点");
        return knowpointServiceImpl.findAll();
    }

    @RequestMapping("/more")
    public void saveKnowpointBean(String knowpointNo,String knowpointName,Long sid,Long pid){
        System.out.println("开始新增");
        System.out.println(knowpointNo);
        System.out.println(knowpointName);
        System.out.println(sid);
        System.out.println(pid);
        KnowpointBean knowpointBean=new KnowpointBean();
        SubjectBean subjectBean=new SubjectBean();
        ProjectBean projectBean=new ProjectBean();
        projectBean.setId(pid);
        subjectBean.setId(sid);
        subjectBean.setProjectBean(projectBean);
        knowpointBean.setKnowpointNo(knowpointNo);
        knowpointBean.setKnowpointName(knowpointName);
        knowpointBean.setSubjectBean(subjectBean);
        knowpointServiceImpl.saveKnowpointBean(knowpointBean);
        System.out.println("新建完成");
    }

    @RequestMapping("/findOneByCondition")
    public List<KnowpointBean> findByCondition(String knowpointName, Long sid,@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date createTime){
        System.out.println("开始根据条件查询知识点");
        System.out.println(knowpointName);
        System.out.println(sid);
        System.out.println(createTime);
        KnowpointBean knowpointBean=new KnowpointBean();
        SubjectBean subjectBean=new SubjectBean();
        subjectBean.setId(sid);
        knowpointBean.setKnowpointName(knowpointName);
        knowpointBean.setSubjectBean(subjectBean);
        knowpointBean.setCreateTime(createTime);
        System.out.println(knowpointBean);
        System.out.println(subjectBean);
        List<KnowpointBean> k = knowpointServiceImpl.findOneByCondition(knowpointBean);
        System.out.println(k);
        return k;

    }

    @RequestMapping("/change")
    public void change(String knowpointName,Long id){
        System.out.println("开始更改");
        System.out.println(id);
        System.out.println(knowpointName);
        KnowpointBean knowpointBean=new KnowpointBean();
        knowpointBean.setKnowpointName(knowpointName);
        knowpointBean.setId(id);
        knowpointServiceImpl.update(knowpointBean);
        System.out.println("更改完成");
    }

    @RequestMapping("/del")
    public void del(Long id){
        System.out.println("开始删除");
        knowpointServiceImpl.delete(id);
        System.out.println("删除完成");
    }

    @RequestMapping("/getknowpoint")
    public String[] getknowpoint(){
        return knowpointServiceImpl.getknowpointName();
    }
}
